import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)
// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/** note: submenu only apppear when children.length>=1
*   detail see  https://panjiachen.github.io/vue-element-admin-site/#/router-and-nav?id=sidebar
**/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    roles: ['admin','editor']     will control the page roles (you can set multiple roles)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if fasle ,the page will no be cached(default is false)
  }
**/
// 不需要进行权限认证的路由
export const constantRouterMap = [
  { path: '/login', component: _import('login/index'), hidden: true },
  { path: '/authredirect', component: _import('login/authredirect'), hidden: true },
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout, // 使用默认的基础布局
    redirect: '/selfCenter/homePage', // 面包屑中的路由
    name: 'selfCenter', // 定义路由的名称，必须声明
    alwaysShow: true, // 总是显示展开箭头
    meta: { title: 'selfCenter', icon: 'selfCenter' },
    children: [{
      path: 'selfCenter/homePage',
      component: _import('self-center/homePage'), // 自定义的_import实现路由的懒加载
      name: 'selfCenter-homePage',
      meta: { title: 'homePage', icon: 'index', noCache: true }
    },
    {
      path: 'selfCenter/index',
      component: _import('self-center/index'), // 自定义的_import实现路由的懒加载
      name: 'selfCenter-index',
      meta: { title: 'baseInfo', icon: 'baseInfo', noCache: true }
    }]
  }
  // {
  //   path: '/documentation',
  //   component: Layout,
  //   redirect: '/documentation/index',
  //   children: [{
  //     path: 'index',
  //     component: _import('documentation/index'),
  //     name: 'documentation',
  //     meta: { title: 'documentation', icon: 'documentation', noCache: true }
  //   }]
  // }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

// 需要进行权限认证的路由
export const asyncRouterMap = [
  {
    id: '1',
    path: '/ucenter', // 用户中心
    component: Layout,
    redirect: '/ucenter/index',
    name: 'ucenter',
    alwaysShow: true,
    meta: { roles: ['admin'], title: 'ucenter', icon: 'ucenter' },
    children: [{ // 用户管理
      id: '10',
      path: 'index',
      component: _import('self-center/index'), // 自定义的_import实现路由的懒加载
      name: 'ucenter-index',
      meta: { roles: ['admin', 'editor'], title: 'user_manager', icon: 'user_manager', noCache: true }
    }]
  },
  {
    id: '2',
    path: '/upmsSystem', // 权限管理系统
    component: Layout,
    redirect: '/upmsSystem/index',
    name: 'upmsSystem',
    alwaysShow: true,
    meta: { roles: ['admin'], title: 'upms', icon: 'upms' },
    children: [{ // 系统管理
      id: '20',
      path: 'index',
      component: _import('upms/system'),
      name: 'upmsSystem-index',
      meta: { roles: ['admin'], title: 'system', icon: 'system', noCache: true }
    },
    { // 组织管理
      id: '21',
      path: 'organization',
      component: _import('upms/organization'),
      name: 'upmsSystem-organization',
      meta: { roles: ['admin'], title: 'organization', icon: 'organization', noCache: true }
    },
    { // 角色管理
      id: '22',
      path: 'role',
      component: _import('upms/role'),
      name: 'upmsSystem-role',
      meta: { roles: ['admin'], title: 'role', icon: 'role', noCache: true }
    },
    { // 用户管理
      id: '23',
      path: 'user',
      component: _import('upms/user'),
      name: 'upmsSystem-user',
      meta: { roles: ['admin'], title: 'user', icon: 'user', noCache: true }
    },
    { // 权限管理
      id: '24',
      path: 'power',
      component: _import('upms/permission'),
      name: 'upmsSystem-power',
      meta: { roles: ['admin'], title: 'power', icon: 'power', noCache: true }
    }]
  },
  {
    id: '3',
    path: '/monitor', // 监控中心
    component: Layout,
    redirect: '/monitor/index',
    name: 'monitor',
    alwaysShow: true,
    meta: { roles: ['admin'], title: 'monitor', icon: 'monitor' },
    children: [{ // 请求监控
      id: '30',
      path: 'index',
      component: _import('monitor/index'),
      name: 'monitor_index',
      meta: { roles: ['admin'], title: 'request_monitor', icon: 'request_monitor', noCache: true }
    },
    { // 服务调用追踪
      id: '31',
      path: 'zipkin',
      component: _import('monitor/zipkin'),
      name: 'monitor_zipkin',
      meta: { roles: ['admin'], title: 'monitor_zipkin', icon: 'monitor_zipkin', noCache: true }
    },
    {
      id: '32',
      path: 'bigShow',
      component: _import('monitor/bigShow'),
      name: 'monitor_bigShow',
      meta: { roles: ['admin'], title: 'monitor_serviceRank', icon: 'monitor_zipkin', noCache: true }
    }]
  },
  {
    id: '4',
    path: '/ops', // 运维中心
    component: Layout,
    redirect: '/ops/index',
    name: 'ops',
    alwaysShow: true,
    meta: { roles: ['admin'], title: 'ops', icon: 'ops' },
    children: [{
      id: '41',
      path: 'ops_service',
      component: _import('ops/serviceManage'),
      name: 'ops_service',
      meta: { roles: ['admin'], title: 'ops_service', icon: 'ops_service' }
    },
    {
      id: '42',
      path: 'ops_config_server',
      component: _import('ops/config_center'),
      name: 'ops_config_center',
      meta: { roles: ['admin'], title: 'config_center', icon: 'config_center', noCache: true }
    }]
  },
  {
    id: '5',
    path: '/devCenter', // 开发中心
    component: Layout,
    redirect: '/decCenter/index',
    name: 'devCenter',
    alwaysShow: true,
    meta: { roles: ['admin', 'dev'], title: 'devCenter', icon: 'devCenter' },
    children: [{
      id: '50',
      path: 'index',
      component: _import('dev-center/index'),
      name: 'devCenter-index',
      meta: { roles: ['admin', 'dev'], title: 'devDocument', icon: 'devDocument', noCache: true }
    }]
  },
  // {
  //   path: '/permission',
  //   component: Layout,
  //   redirect: '/permission/index',
  //   meta: { roles: ['admin'] }, // you can set roles in root nav
  //   children: [{
  //     path: 'index',
  //     component: _import('permission/index'),
  //     name: 'permission',
  //     meta: {
  //       title: 'permission',
  //       icon: 'lock',
  //       roles: ['admin'] // or you can only set roles in sub nav
  //     }
  //   }]
  // },
  // {
  //   path: '/icon',
  //   component: Layout,
  //   children: [{
  //     path: 'index',
  //     component: _import('svg-icons/index'),
  //     name: 'icons',
  //     meta: { title: 'icons', icon: 'icon', noCache: true }
  //   }]
  // },
  //
  // {
  //   path: '/components',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'component-demo',
  //   meta: {
  //     title: 'components',
  //     icon: 'component'
  //   },
  //   children: [
  //     { path: 'tinymce', component: _import('components-demo/tinymce'), name: 'tinymce-demo', meta: { title: 'tinymce' }},
  //     { path: 'markdown', component: _import('components-demo/markdown'), name: 'markdown-demo', meta: { title: 'markdown' }},
  //     { path: 'json-editor', component: _import('components-demo/jsonEditor'), name: 'jsonEditor-demo', meta: { title: 'jsonEditor' }},
  //     { path: 'dnd-list', component: _import('components-demo/dndList'), name: 'dndList-demo', meta: { title: 'dndList' }},
  //     { path: 'splitpane', component: _import('components-demo/splitpane'), name: 'splitpane-demo', meta: { title: 'splitPane' }},
  //     { path: 'avatar-upload', component: _import('components-demo/avatarUpload'), name: 'avatarUpload-demo', meta: { title: 'avatarUpload' }},
  //     { path: 'dropzone', component: _import('components-demo/dropzone'), name: 'dropzone-demo', meta: { title: 'dropzone' }},
  //     { path: 'sticky', component: _import('components-demo/sticky'), name: 'sticky-demo', meta: { title: 'sticky' }},
  //     { path: 'count-to', component: _import('components-demo/countTo'), name: 'countTo-demo', meta: { title: 'countTo' }},
  //     { path: 'mixin', component: _import('components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin' }},
  //     { path: 'back-to-top', component: _import('components-demo/backToTop'), name: 'backToTop-demo', meta: { title: 'backToTop' }}
  //   ]
  // },
  //
  // {
  //   path: '/charts',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'charts',
  //   meta: {
  //     title: 'charts',
  //     icon: 'chart'
  //   },
  //   children: [
  //     { path: 'keyboard', component: _import('charts/keyboard'), name: 'keyboardChart', meta: { title: 'keyboardChart', noCache: true }},
  //     { path: 'line', component: _import('charts/line'), name: 'lineChart', meta: { title: 'lineChart', noCache: true }},
  //     { path: 'mixchart', component: _import('charts/mixChart'), name: 'mixChart', meta: { title: 'mixChart', noCache: true }}
  //   ]
  // },
  //
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table/complex-table',
  //   name: 'example',
  //   meta: {
  //     title: 'example',
  //     icon: 'example'
  //   },
  //   children: [
  //     {
  //       path: '/example/table',
  //       component: _import('example/table/index'),
  //       redirect: '/example/table/complex-table',
  //       name: 'Table',
  //       meta: {
  //         title: 'Table',
  //         icon: 'table'
  //       },
  //       children: [
  //         { path: 'dynamic-table', component: _import('example/table/dynamicTable/index'), name: 'dynamicTable', meta: { title: 'dynamicTable' }},
  //         { path: 'drag-table', component: _import('example/table/dragTable'), name: 'dragTable', meta: { title: 'dragTable' }},
  //         { path: 'inline-edit-table', component: _import('example/table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'inlineEditTable' }},
  //         { path: 'tree-table', component: _import('example/table/treeTable/treeTable'), name: 'treeTableDemo', meta: { title: 'treeTable' }},
  //         { path: 'custom-tree-table', component: _import('example/table/treeTable/customTreeTable'), name: 'customTreeTableDemo', meta: { title: 'customTreeTable' }},
  //         { path: 'complex-table', component: _import('example/table/complexTable'), name: 'complexTable', meta: { title: 'complexTable' }}
  //       ]
  //     },
  //     { path: 'tab/index', icon: 'tab', component: _import('example/tab/index'), name: 'tab', meta: { title: 'tab' }}
  //   ]
  // },
  //
  // {
  //   path: '/form',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'form',
  //   meta: {
  //     title: 'form',
  //     icon: 'form'
  //   },
  //   children: [
  //     { path: 'create-form', component: _import('form/create'), name: 'createForm', meta: { title: 'createForm', icon: 'table' }},
  //     { path: 'edit-form', component: _import('form/edit'), name: 'editForm', meta: { title: 'editForm', icon: 'table' }}
  //   ]
  // },
  //
  // {
  //   path: '/error',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   name: 'errorPages',
  //   meta: {
  //     title: 'errorPages',
  //     icon: '404'
  //   },
  //   children: [
  //     { path: '401', component: _import('errorPage/401'), name: 'page401', meta: { title: 'page401', noCache: true }},
  //     { path: '404', component: _import('errorPage/404'), name: 'page404', meta: { title: 'page404', noCache: true }}
  //   ]
  // },
  //
  // {
  //   path: '/error-log',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [{ path: 'log', component: _import('errorLog/index'), name: 'errorLog', meta: { title: 'errorLog', icon: 'bug' }}]
  // },
  //
  // {
  //   path: '/excel',
  //   component: Layout,
  //   redirect: '/excel/export-excel',
  //   name: 'excel',
  //   meta: {
  //     title: 'excel',
  //     icon: 'excel'
  //   },
  //   children: [
  //     { path: 'export-excel', component: _import('excel/exportExcel'), name: 'exportExcel', meta: { title: 'exportExcel' }},
  //     { path: 'export-selected-excel', component: _import('excel/selectExcel'), name: 'selectExcel', meta: { title: 'selectExcel' }},
  //     { path: 'upload-excel', component: _import('excel/uploadExcel'), name: 'uploadExcel', meta: { title: 'uploadExcel' }}
  //   ]
  // },
  //
  // {
  //   path: '/zip',
  //   component: Layout,
  //   redirect: '/zip/download',
  //   alwaysShow: true,
  //   meta: { title: 'zip', icon: 'zip' },
  //   children: [{ path: 'download', component: _import('zip/index'), name: 'exportZip', meta: { title: 'exportZip' }}]
  // },
  //
  // {
  //   path: '/theme',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [{ path: 'index', component: _import('theme/index'), name: 'theme', meta: { title: 'theme', icon: 'theme' }}]
  // },
  //
  // {
  //   path: '/clipboard',
  //   component: Layout,
  //   redirect: 'noredirect',
  //   children: [{ path: 'index', component: _import('clipboard/index'), name: 'clipboardDemo', meta: { title: 'clipboardDemo', icon: 'clipboard' }}]
  // },
  //
  // {
  //   path: '/i18n',
  //   component: Layout,
  //   children: [{ path: 'index', component: _import('i18n-demo/index'), name: 'i18n', meta: { title: 'i18n', icon: 'international' }}]
  // },

  { path: '*', redirect: '/404', hidden: true }
]
